#include "GameRPCHandler.h"
#include "boost/bind.hpp"
#include "DispatchHandler.h"

#include "RPC_dispatch.pb.h"

void GameRpcHandler::init()
{
	regRpcHandler("requestHandle", boost::bind(&GameRpcHandler::remote_dispatch, this, _1));
}

google::protobuf::Message* GameRpcHandler::remote_dispatch(const string& params)
{

	RPC_RequestHandle proto;
	try
	{
		proto.ParseFromString(params);

		Dispatcher.execMessageHandler(proto.msg_id(), proto.net_id(), &proto);
	}
	catch(const std::exception& e)
	{
		LOGE("Parse protobuf error ==> [ %s ]", e.what());
	}

	return nullptr;
}
